/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.regex.Pattern;

/**
 * <p>Project: javase - Reg6
 * <p>Powered by webrx On 2021-12-07 10:09:16
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reg6 {
    public static void main(String[] args) {
        var rand = new Random();
        var sbu = new StringBuilder("1");
        var ops = new String[]{"", "+", "-"};
        for (int i = 2; i <= 9; i++) {
            sbu.append(ops[rand.nextInt(3)].concat(String.valueOf(i)));
        }
        System.out.printf("%s%n", sbu.toString());

        String str = "123-4-5-67+8-9";
        //使用正则表达式搜索数字 "-?\\d+"
        var p = Pattern.compile("-{0,1}[0-9]{1,}");
        var m = p.matcher(str);
        int sum = 0;
        while (m.find()) {
            int num = Integer.parseInt(m.group());
            System.out.println(num);
            sum += num;
        }
        System.out.println(sum);
    }
}
